Just one, created in main()
.
The picture shows the executing program
just as the findMax()
method starts running.
Remember that Java uses call by value to pass data into methods.
With array parameters, this means that the parameter holds
the value of the reference to the array.
There is only one array object,
the one created by main()
.findMax()
x
.
Here are some details:
ArrayDemo
is shown in dotted lines because it is a class definition,
not an object.ArrayDemo
's static method main()
is running.ar1
refers to the array object.operate
refers to an ArrayOps
object.findMax()
operate
is called with ar1
as a parameter.x
refers to the
same object as does the variable ar1
in main()
.
Now the findMax()
method runs, using
x
to refer to the array it is working with.
When it finishes running, control returns to main()
.
Usually you do not think about things in such excruciating detail. You would think "call a method to find the maximum" and would write
operate.findMax( ar1 );
But sometimes you really need to know what is going on. Please look the picture over and read over the details a few times. If you rush through this material, you risk missing concepts that are necessary for understanding future topics.
(Test of Understanding: )
Could the
main()
method create a second array and use the
findMax()
method with it?